﻿Imports System.Data.SqlClient
Public Class clsKmsAcumulado
    Private mintIdAcumulado As Integer
    Private mintIdAutobus As Integer
    Private mdblKmsAcumulados As Double
    Public Property IdAcumulado() As Integer
        Get
            Return mintIdAcumulado
        End Get
        Set(ByVal value As Integer)
            mintIdAcumulado = value
        End Set
    End Property
    Public Property IdAutobus() As Integer
        Get
            Return mintIdAutobus
        End Get
        Set(ByVal value As Integer)
            mintIdAutobus = value
        End Set
    End Property
    Public Property KmsAcumulados() As Double
        Get
            Return mdblKmsAcumulados
        End Get
        Set(ByVal value As Double)
            mdblKmsAcumulados = value
        End Set
    End Property
    Public Sub New()
        mintIdAcumulado = 0
        mintIdAutobus = 0
        mdblKmsAcumulados = 0
    End Sub
    Public Sub Insertar()
        Dim sql As String = "Insert Into KmsAcumulado (" & _
                             "IdAutobus," & _
                            "KmsAcumulado)" & _
                            "VALUES (" & _
                            "@IdAutobus," & _
                            "@KmsAcumulado)" & _
                            " SELECT SCOPE_IDENTITY()"


        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim Command As New SqlCommand(sql, cnConn)

        Command.Parameters.AddWithValue("IdAutobus", mintIdAutobus)
        Command.Parameters.AddWithValue("KmsAcumulado", mdblKmsAcumulados)

        cnConn.Open()
        Try
            IdAcumulado = Convert.ToInt32(Command.ExecuteScalar)
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Aviso")

        End Try


        If IdAcumulado > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible insertar el acumulado ", MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If
    End Sub
    Public Sub Actualizar()

        Dim strSqlQry As String
        Dim cnConn As New SqlConnection

        cnConn.ConnectionString = CitraConnection
        strSqlQry = "Update KmsAcumulados Set " & _
                    "KmsAcumulados=@KmsAcumulados " & _
                    "Where IdAutobus=@IdAutobus"


        Dim Command As New SqlCommand(strSqlQry, cnConn)

        Command.Parameters.AddWithValue("IdAutobus", mintIdAutobus)
        Command.Parameters.AddWithValue("KmsAcumulados", mdblKmsAcumulados)
        cnConn.Open()

        Dim RowsAffected As Integer

        Try
            RowsAffected = Command.ExecuteNonQuery
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Aviso")

        End Try


        If RowsAffected > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible actualizar el liquidación ", MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If



    End Sub
End Class
